﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair.Base
{
    public partial class frmupdatepwd : Form
    {
        public frmupdatepwd()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button1_Click(object sender, EventArgs e)
        {
            chuanzhi ca = new chuanzhi();
            if (ca.checkpwd(txtoldpwd.Text) == true)
            {
                if (txtnewpwd.Text == txtageinpwd.Text)
                {
                    try
                    {
                        string sql = string.Format("UPDATE [LoginUser] SET [LoginPassword] ='{0}' WHERE LoginUserID='{1}'", txtnewpwd.Text, chuanzhi.userID);
                        SqlConnection conn = new SqlConnection(constr);
                        conn.Open();
                        SqlCommand comm = new SqlCommand(sql, conn);
                        comm.ExecuteNonQuery();
                        MessageBox.Show("密码修改成功！");
                        conn.Close();
                    }
                    catch(Exception ee)
                    {
                        MessageBox.Show("密码修改失败，原因为"+ee.Message);
                    }
                }
                else
                {
                    MessageBox.Show("两次新密码输入不一致！");
                }
            }
            else
            {
                MessageBox.Show("旧密码错误！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
